package com.yubest.demo.controller;

import com.yubest.demo.dto.DemoRespDTO;
import com.yubest.demo.dto.Response;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;

/**
 * @Author hweiyu
 * @Description
 * @Date 2021/3/1 14:01
 */
@RestController
public class DemoController {

    @Value("classpath:a.png")
    private Resource img;

    /**
     * @return
     */
    @GetMapping(value = "/test")
    public Response<DemoRespDTO> test() {
        DemoRespDTO respDTO = new DemoRespDTO();
        respDTO.setA(1);
        respDTO.setB(new DemoRespDTO.BBean().setC("ccc").setD("ddd"));
        respDTO.setE(Arrays.asList("e1", "e2"));
        respDTO.setPassword("123456");
        respDTO.setF("1234567890987654321");
        try {
            respDTO.setImg(Files.readAllBytes(img.getFile().toPath()));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Response.success(respDTO);
    }

}
